import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.util.ArrayList;


public class createNewPlayer  extends Thread  {
	private static ArrayList<Socket> players = new ArrayList<Socket>();
	private Socket socket;
	public createNewPlayer(Socket socket){
		this.socket = socket;
	}
	public void run() {
		try {
			// 增加新的使用者
			players.add(socket);

			// 取得網路串流
			BufferedReader br = new BufferedReader(
					new InputStreamReader(socket.getInputStream()));

			// 當Socket已連接時連續執行
			while (socket.isConnected()) {
				// 取得網路串流的訊息
				String msg = br.readLine();

				// 輸出訊息
				System.out.println(msg);

				// 廣播訊息給其它的客戶端
				server.castMsg(msg, players);
			}

		} catch (IOException e) {

		}

		// 移除客戶端
		players.remove(socket);
	}
}
